Function Handles

A function handle is a data type in MATLAB that contains information used to reference a function. When creating a function handle, MATLAB saves all information related to the function to be run within the handle. Function handles are often passed to other functions in parameter lists and then used with the eval function to run the function they belong to. MATLAB function handles can not only reference functions, but they often represent collections of function methods. After overloading these methods, you can control different parameter types: when creating a handle for a function, MATLAB quickly scans for internal methods or M-file methods with that name. When processing a function handle, MATLAB only considers those functions saved in the handle.

The main benefits of using function handles are:

Passing information obtained from functions to other functions;

Mastering all methods of an overloaded function;

Allowing broader access to sub-functions and private functions;

Ensuring reliability of function calculations;

Reducing the number of fields required to define functions;

Improving repetitive operations;

Manipulating handles in arrays, structures, and cell arrays;

Passing function handles as variables to another function in a call.

The creation and use of function handles will be introduced in detail in Chapter 3.